//
//  UINavigationBar+CustomImage.m
//  studip
//
//  Created by Rafael Bugajewski on 04/21/10.
//  Copyright 2010 Juicy Cocktail. All rights reserved.
//

#import "UINavigationBar+CustomImage.h"

@implementation UINavigationBar (CustomImage)

//- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
//{
//	[super drawLayer:layer inContext:ctx];
//	
//	if ([self isMemberOfClass: [UINavigationBar class]])
//	{
//		UIImage *image = [UIImage imageNamed:@"woodNavibarGlow.png"];
//		CGContextClip(ctx);
//		CGContextTranslateCTM(ctx, 0, image.size.height);
//		CGContextScaleCTM(ctx, 1.0, -1.0);
//		CGContextDrawImage(ctx, CGRectMake(0, 0, self.frame.size.width, self.frame.size.height), image.CGImage);
//	} else
//	{
//		[super drawLayer:layer inContext:ctx];
//	}
//}

-(void)setBackgroundImage:(UIImage *)image withTag:(NSInteger)bgTag
{
  if (!image)
  {
    return;
  }
  
  UIImageView *aTabBarBackground = [[[UIImageView alloc] initWithImage:image] autorelease];
  aTabBarBackground.frame = CGRectMake(0,0,self.frame.size.width,self.frame.size.height);
  aTabBarBackground.tag = bgTag;
  
  [self addSubview:aTabBarBackground];
  [self sendSubviewToBack:aTabBarBackground];
}

/* input: The tag you chose to identify the view */
-(void)resetBackground:(NSInteger)bgTag
{
  [self sendSubviewToBack:[self viewWithTag:bgTag]];
}

- (void)removeBackgroundImage:(NSInteger)aTag
{
  [[self viewWithTag:aTag] removeFromSuperview];
}

@end
